#ifndef ANCHORROOM_H
#define ANCHORROOM_H

#include <QMainWindow>
#include <QListWidgetItem>
#include <QTimer>
#include <QBuffer>
#include <QProcess>

#include <QLabel>
#include <QList>
#include <QPropertyAnimation>

#include <QPixmap>
#include <QScreen>
#include <QCamera>
#include <QCameraInfo>
#include <QCameraImageCapture>
#include <QImageReader>

#include "clienthandler.h"
#include "../common/singleton.h"

namespace Ui {
class AnchorRoom;
}

class AnchorRoom : public QMainWindow
{
    Q_OBJECT

    explicit AnchorRoom(QWidget *parent = nullptr);
    friend class SingleTon<AnchorRoom>;
public:

    ~AnchorRoom();
    //房间操作
    void createRoom(QString& anchor, QString& roomid);
    void joinRoom(QString& anchor, QString& roomid);
    void setRoom(QString& anchor, QString& roomid);
    void addAudience( QString audi);
    void deleAudience(QString& audi);
    void clearlist();
//直播
    void showCamera(const QByteArray& data);
    void showImg(const QByteArray& data);

    //摄像头直播
    void initCameraVideoSet();
    void initCamera();
    void initImgcap();
    void CaptureCamera();
    void on_imgcaptured(int id, QImage img);
    void startCameraVideo();
    void stopCameraVideo();

    //直播屏幕
    void CaptureScreen();
    void startDeskVideo();
    void stopDeskVideo();

    //弹幕
    void appendText(const QString& text);
    void appendbarrage(QString& message);

private slots:
    void on_actionQuit_triggered();

    void on_pushButton_clicked();

    void on_chkMIC_clicked(bool checked);

    void on_chkmute_clicked(bool checked);

    void on_chkbarrage_clicked(bool checked);

    void on_lineEdit_returnPressed();

    void on_rbcamera_clicked(bool checked);

    void on_rbdesktop_clicked(bool checked);

private:
//房间管理
    Ui::AnchorRoom *ui;
    QString Anchor;
    QString RoomID;

//camera视频流
    QCamera *curCamera=Q_NULLPTR;
    QCameraImageCapture *imgcap=Q_NULLPTR;
    QTimer *CaptureRate=Q_NULLPTR;
    QPixmap pix;
    QBuffer imgbuffer;

    QScreen *screen;
    QProcess *process;

//弹幕
    int barragecount;
    QList<QPropertyAnimation*> animations;

    // QWidget interface
protected:
    virtual void closeEvent(QCloseEvent *event);
};

#endif // ANCHORROOM_H
